package com.smh.a04ziDingYiExceptionDemo1;

import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        GirlFriend girlFriend = new GirlFriend();
        String name;
        int age;
        Scanner scanner = new Scanner(System.in);

        while (true) {
            try {
                System.out.println("姓名");
                name = scanner.nextLine();
                girlFriend.setName(name);
                System.out.println("年龄");
                String ageStr = scanner.nextLine();
                age = Integer.parseInt(ageStr);
                girlFriend.setAge(age);
                break;
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (NameFormatException e) {
                e.printStackTrace();
            } catch (AgeOutOfBoundsException e) {
                e.printStackTrace();
            }
        }
        System.out.println(girlFriend);

    }
}
